﻿#region 命名空间

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Sharp.Domain.PlatformBoundedContext.MessageModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.OrgModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.PermissionModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.PersonModule.Aggregates;
using Sharp.Domain.Model;
using Sharp.Infrastructure;

#endregion

namespace Sharp.Domain.PlatformBoundedContext.UserModule.Aggregates
{
    /// <summary>
    ///     用户
    /// </summary>
    public partial class User : AggregateRoot, IStandardEntity, IStandardState
    {
        public User()
        {
            Roles = new List<Role>();
            UserGroups = new List<UserGroup>();
            Permissions = new List<Permission>();
        }

        /// <summary>
        ///     获取或设置当前客户的用户名。
        /// </summary>
        [Index]
        public string UserName { get; set; }

        /// <summary>
        ///     获取或设置当前客户的登录密码。
        /// </summary>
        public string Password { get; set; }

        /// <summary>
        ///     获取或设置当前客户的电子邮件地址。
        /// </summary>
        public string Email { get; set; }

        /// <summary>
        /// 是否审核
        /// </summary>
        public bool IsApproved { get; set; }
        /// <summary>
        /// 获取一个值，该值指示成员资格用户是否因被锁定而无法进行验证。
        /// </summary>
        public bool IsLockedOut { get; set; }

        [DefaultValue(1)]
        public EntityStateOperate EntityState { get; set; }
        /// <summary>
        ///     获取或设置用户账户最后一次登录的时间。
        /// </summary>
        public DateTime? LastLogonTime { get; set; }
        /// <summary>
        /// 获取或设置用户最后一次登录的IP
        /// </summary>
        public string LastLogonIp { get; set; }
        /// <summary>
        /// 获取或设置用户账户注册的时间。
        /// </summary>
        [Required]
        public DateTime RegisteredTime { get; set; }
        /// <summary>
        /// 获取上次更新成员资格用户的密码的日期和时间
        /// </summary>
        public DateTime LastPasswordChangedDate { get; set; }
        /// <summary>
        /// 获取或设置成员资格用户的特定于应用程序的信息
        /// </summary>
        [StringLength(255)]
        public string Comment { get; set; }

        /// <summary>
        /// 添加日期
        /// </summary>
        /// <value>添加日期</value>
        public System.DateTime? CheckInTime { get; set; }
        /// <summary>
        /// 录入员的id
        /// </summary>
        /// <value>录入员的id</value>
        public Guid? CheckInUserId { get; set; }
        /// <summary>
        /// 修改时间
        /// </summary>
        /// <value>修改时间</value>
        public System.DateTime? ModifiTime { get; set; }
        /// <summary>
        /// 修改数据的用户Id
        /// </summary>
        /// <value>修改数据的用户Id</value>
        public Guid? ModifiedUserId { get; set; }

        /// <summary>
        /// 用户的扩展资料
        /// </summary>
        [ForeignKey("Id")]
        public UserProfile Profile { get; set; }
        /// <summary>
        /// 用户对应的个人
        /// </summary>
        public Person Person { get; set; }

        /// <summary>
        ///     角色
        /// </summary>
        public virtual ICollection<Role> Roles { get; set; }

        /// <summary>
        ///     用户组
        /// </summary>
        public virtual ICollection<UserGroup> UserGroups { get; set; }

        /// <summary>
        ///     用户权限
        /// </summary>
        public virtual ICollection<Permission> Permissions { get; set; }

        #region 方法

        /// <summary>
        ///     返回表示当前Object的字符串。
        /// </summary>
        /// <returns>表示当前对象的字符串。</returns>
        public override string ToString()
        {
            return UserName;
        }

        #endregion


        /// <summary>
        /// 已授权组织
        /// </summary>
        public virtual ICollection<Org> AuthorizedOrgs { get; set; }

        /// <summary>
        /// 登录哪个系统
        /// </summary>
        /// <param name="systemCode"></param>
        public void LoginWhichSystem(string systemCode)
        {
            SystemCode = systemCode;
        }
        /// <summary>
        /// 系统代号
        /// </summary>
        [NotMapped]
        public string SystemCode { get; set; }

    }
}